<?php
namespace App\Http\Controllers\Admin;

use App\Http\Controllers\AdapterWebController;
use App\Modules\Sale\Sale;
use Illuminate\Http\Request;


class SaleController extends AdapterWebController
{

    /**
     * 添加业务员
     */
    public function addSale(Request $request)
    {
        if($request->isMethod('get')){
            return view('admin.sale.add_sale');
        }
        $postData = $request->all();
        $this->appLayerExec(Sale::class, 'addSale', $postData);
        flash('添加成功')->success();
        return redirect()->back();
    }

    //业务员列表
    public function saleList()
    {
        $res = $this->appLayerExec(Sale::class, 'saleList');
        return view('admin.sale.sale_list',['list'=>$res['res'],'user'=>1,'manager'=>1,'saleListStatus'=>1]);
    }

    //离职,更新
    public function updateSale(Request $request, $id=0,$status=0 ){
        if($status == 1){

        }else{
            if($request->isMethod('get')){
                $sale = \App\Models\Sale\Sale::where('id','=',$id)->first();
                return view('admin.sale.edit_sale',['sale'=>$sale]);
            }
        }
        $postData = $request->all();
        $postData['status'] = $status;
        $postData['id'] = $id;
        $this->appLayerExec(Sale::class, 'updateSale',$postData);
        flash('操作成功')->success();
        return redirect()->back();
    }

    //解绑
    public function unbind(Request $request,$name){
        if($request->isMethod('get')){
            $sale = \App\Models\Sale\Sale::select('name')->get();
            return view('admin.sale.unbind',['name'=>$name,'sale'=>$sale]);
        }
        $postData = $request->all();
        $res = $this->appLayerExec(Sale::class, 'unbind',$postData);
        flash('解绑成功')->success();
        return redirect()->back();
    }
}